﻿@{
    ViewBag.Title = "AssignRoleWindow";
    Layout = null;
}
<script type="text/javascript">
    var Assign = {};
    var userId;
    $(function () {
        userId = $(top.document).find("#hidId").val();
        // console.log(roleId);
        com.ajax({
            url: "/User/GetUserRole",
            type: "POST",
            data: { Id: userId },
            success: function (data) {
                LoadRole(data);
            }
        });

    });

    function LoadRole(r) {

        for (var i = 0; i < r.length; i++) {
            if (r[i].Checked == true) {
                $("<div class='fitAssignPer'><input type='checkbox' checked='true' value='" + r[i].value + "'/>" + r[i].text + "</div>").appendTo(("#divUl"));
            }

            else {
                $("<div class='fitAssignPer'><input type='checkbox' value='" + r[i].value + "'/>" + r[i].text + "</div>").appendTo(("#divUl"));
            }

        }

    }

    Assign.Cancel = function () {
        $("#assignUserDiv").dialog('close');
    }

    Assign.Confirm = function () {
        var roleIds = "";
        var n = 0;
        //1.获取所选角色
        var $roles = $(".fitAssignPer > input:checked").each(function () { roleIds += $(this).val() + ','; n++; });
        if (n >= 1) {
            com.ajax({
                url: "/User/EditUserRole",
                data: { Id: userId, RoleIds: roleIds },
                success: function (data) {
                    com.message(data.state, data.msg, function () {
                        $("#assignUserDiv").dialog('close');
                    })
                }
            });
        }
        else {
            com.message("information", "请勾选一项！");
        }
    }
</script>
<div id="divUl" style="height: 220px; width: 100%; overflow: auto">
</div>
<div class="dialog-bottom">
    <input type="hidden" id="hidAddRole.Action" />
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="Assign.Confirm()">确定</a>
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="Assign.Cancel()">取消</a>
</div>
